<div class="box">
	<div class="box-header">
		<h3 class="box-title"><i class="fa fa-newspaper-o"></i> <?=$this->lang->line("ARTICLES")?> <?=$this->lang->line("YOU_CAN_EDIT")?></h3>
	</div>
	<div class="box-body ">

		<? 
		$this->load->helper('text');
		//Common::pr($articleList); exit; 
		?>

		<table id="articleTable" class="display table table-bordered">
			<thead>
				<tr>
					<th class="text-right w1">#</th>
					<th><?=$this->lang->line("TITLE")?></th>
					<th><?=$this->lang->line("LEAD")?></th>
					<? if(Common::isSuperAdmin()) { ?>
						<th><?=$this->lang->line("EMPHASIZED")?></th>
						<th><?=$this->lang->line("POSITION")?></th>
					<? } ?>
					<th><?=$this->lang->line("ATTACHING")?></th>
					<th><?=$this->lang->line("RECORDING_TIME")?></th>
					<th class="w1 ws"><?=$this->lang->line("OPTIONS")?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				foreach($articleList as $art) {
					$art["artPresenter"] = "N";
					$rowClass = "";
					
					if($art["artTempFlag"] == "I") {
						$rowClass = "warning";
					} elseif($art["artPresenter"] == "I") {
						$rowClass = "success";
					}
					
					echo		"<tr class=\"".$rowClass."\">";
					echo			"<td class=\"vm w1 text-right\"></td>";
					echo			"<td class=\"vm\">".$art["artName"]."</td>";
					echo			"<td class=\"vm\">".character_limiter(strip_tags($art["artLead"]), 400)."</td>";
					if(Common::isSuperAdmin()) {
						echo			"<td class=\"vm text-center\">".($art["artHighlight"] == "I" ? $this->lang->line("YES") : $this->lang->line("NO")).($art["artHighlight"] == "I" ? " <button type=\"button\" data-title=\"".$this->lang->line("EMPHASIZED")."\" data-sort=\"".$art["artHighlight"]."\" class=\"btn btn-xs btn-default\"><span class=\"glyphicon glyphicon-sort\"></span></button>" : "")."</td>";
						echo			"<td class=\"vm text-center\">".$art["szoLname"].($art["artPosition"] != "C" ? " <button type=\"button\" data-title=\"".$art["szoLname"]."\" data-sort=\"".$art["artPosition"]."\" class=\"btn btn-xs btn-default\"><span class=\"glyphicon glyphicon-sort\"></span></button>" : "")."</td>";
					}
					echo			"<td class=\"vm\">".$art["entList"]."</td>";
					echo			"<td class=\"vm text-center\">".Common::dateFromDatabase($art["artCreatetime"])."</td>";
					echo			"<td class=\"vm w1 ws\">";
					echo				"<button class=\"btn btn-xs btn-primary\" data-art=\"".$art["artId"]."\" data-entity=\"ART\" title=\"".$this->lang->line("EDIT")."\" ><span class=\"glyphicon glyphicon-edit\"></span></button>";
					echo				"&nbsp;<button class=\"btn btn-xs btn-primary ".($art["artTempFlag"] != "I" ? "disabled" : "")."\" ".($art["artTempFlag"] ? "data-art-publication=\"".$art["artId"]."\" data-publication=\"1\" data-entity=\"ART\"" : "")." title=\"".$this->lang->line("PUBLICATION")."\"><span class=\"glyphicon glyphicon-thumbs-up\"></span></button>";
					echo				"&nbsp;<button class=\"btn btn-xs btn-primary ".($art["artTempFlag"] != "I" ? "disabled" : "")."\" ".($art["artTempFlag"] ? "data-art-publication=\"".$art["artId"]."\" data-publication=\"0\" data-entity=\"ART\"" : "")." title=\"".$this->lang->line("CANCELLING_OF_UNPUBLISHED_DATA")."\"><span class=\"glyphicon glyphicon-thumbs-down\"></span></button>";
					echo				"&nbsp;<button class=\"btn btn-xs btn-primary ".($art["artPresenter"] ? "" : "disabled")."\" ".($art["artPresenter"] ? "data-art-publication=\"".$art["artId"]."\" data-publication=\"2\" data-entity=\"ART\"" : "")." title=\"".$this->lang->line("CANCELLING_OF_PUBLISHED_DATA")."\"><span class=\"glyphicon glyphicon-hand-left\"></span></button>";
					echo				"&nbsp;<a class=\"btn btn-xs btn-primary\" href=\"".site_url("preview/".$art["artUrlName"])."\" onclick=\"window.open(this.href); return false;\" title=\"".$this->lang->line("PREVIEW")."\"><span class=\"glyphicon glyphicon-share-alt\"></span></a>";
					echo				"&nbsp;<button class=\"btn btn-xs btn-danger\" data-art-delete=\"".$art["artId"]."\" data-entity=\"ART\" title=\"".$this->lang->line("DELETE")."\"><span class=\"glyphicon glyphicon-remove-circle\"></span></button>";
					echo			"</td>";
					echo		"</tr>";
				}
				?>
			</tbody>
		</table>

		<script>
			$(document).ready( function () {

				var articleTable = $('#articleTable').DataTable({
					"language": {
						"url": "<?=MEDIA?>admin_lte/DataTables-1.10.3/localization/en.lang"
					},
					"autoWidth": false,
					"columnDefs": [{
						"searchable": false,
						"orderable": false,
						"targets": 0
					}, {
						"searchable": false,
						"orderable": false,
						"targets": -1
					}],
					"order": [[ 1, 'asc' ]],
					stateSave: true
				});

				articleTable.on('draw.dt', function () {
					articleTable.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
						$(cell).addClass('text-right');
						cell.innerHTML = i+1 + '.';
					});
					eventRebind();
					$('#articleTable').removeClass('hidden');
				});

				articleTable.on( 'init.dt', function () {
					$('#articleTable_length').append('<button class="btn btn-sm btn-success" style="margin-left: 20px;" data-art="-1" data-entity="ART"><span class="glyphicon glyphicon-plus"></span> <?=$this->lang->line("ADD_NEW")?></button>');
					eventRebind();
				});

			});

			var aktImageE;

			function eventRebind() {
				$('button[data-art]').unbind('click').on('click', function(e) {
					e.preventDefault();
					$this = $(this);
					$.ajax({
						type: "POST",
						cache: false,
						data: { ID: $this.data("art") },
						url: '<?=site_url("admin_lte/article_edit")?>',
						beforeSend: function() {
							$('#studyEditorModal .modal-title').html(($this.data('art') == '-1' ? '<?=$this->db->escape_str($this->lang->line("ADD_NEW"))?>' : '<?=$this->lang->line("EDIT")?>') + ' ' + '<?=strtolower($this->lang->line("ARTICLE"))?>');
							$('#studyEditorModal .modal-body form').html('<?=$this->db->escape_str($this->lang->line("PLEASE_WAIT,_PROCESSING_IN_PROGRESS"))?>');
							$('#studyEditorModal').modal('toggle');
						},
						success: function (result) {
							$('#studyEditorModal button.btn-success').data('url', '<?=site_url("admin_lte/article_insert_update")?>');
							$('#studyEditorModal .modal-body form').html(result);
						},
						error: function (error) {}
					});
				});

				$('button[data-sort]').unbind('click').on('click', function(e) {
					e.preventDefault();
					$this = $(this);
					$.ajax({
						type: "POST",
						cache: false,
						data: { artPosition: $this.data("sort") },
						url: '<?=site_url("admin_lte/articles_sort")?>',
						beforeSend: function() {
							$('#studyDisplayModal .modal-title').html($this.data('title'));
							$('#studyDisplayModal .modal-body').html('<?=$this->db->escape_str($this->lang->line("PLEASE_WAIT,_PROCESSING_IN_PROGRESS"))?>');
							$('#studyDisplayModal').modal('toggle');
						},
						success: function (result) {
							$('#studyDisplayModal .modal-body').html(result);
						},
						error: function (error) {}
					});
				});

				$('button[data-art-delete]').unbind('click').on('click', function() {
					$this = $(this);
					$('#studyDeleteModal .modal-title').html('<?=$this->lang->line("DELETE")?>');
					$('#studyDeleteModal .modal-body form').html('<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_DELETE_THE_ITEM"))?>');
					$('#studyDeleteModal .modal-body form').append('<input type="hidden" name="del" value="true" /><input type="hidden" name="artId" value="' + $this.data('artDelete') + '" />');
					$('#studyDeleteModal button.btn-danger').data('url', '<?=site_url("admin_lte/article_insert_update");?>');
					$('#studyDeleteModal').modal('toggle');
				});

				$('button[data-art-publication]').unbind('click').on('click', function() {
					$this = $(this);
					$('#studyConfirmModal .modal-title').html('<?=$this->lang->line("CONFIRMATION")?>');
					var bodyFormHtml = '';
					switch($this.data('publication')) {
						case 0: { bodyFormHtml = '<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_CANCEL_THE_UNPUBLISHED_DATA"))?>'; } break;
						case 1: { bodyFormHtml = '<?=$this->db->escape_str($this->lang->line("ARE_YOU_SURE_YOU_WOULD_LIKE_TO_PUBLISH_THE_ITEMS"))?>'; } break;
						case 2: { bodyFormHtml = '<?=$this->db->escape_str($this->lang->line("ALL_UNPUBLISHED_DATA_WILL_BE_ERASED_ARE_YOU_SURE_TO_CONTINUE"))?>'; } break;
					}
					$('#studyConfirmModal .modal-body form').html(bodyFormHtml);
					$('#studyConfirmModal .modal-body form').append('<input type="hidden" name="publish" value="' + $this.data('publication') + '" /><input type="hidden" name="ID" value="' + $this.data('artPublication') + '" />');
					$('#studyConfirmModal button.btn-success').data('url', '<?=site_url("admin_lte/article_insert_update");?>');
					$('#studyConfirmModal').modal('toggle');
				});

				$('button[data-art-image]').unbind('click').on('click', function(e) {
					e.preventDefault();
					$this = $(this);
					aktImageE = $this;
					imageDisplayRefresh($this);
				});

			}

		</script>

	</div>
</div>